package com.example.qa_back.controller;

import com.example.qa_back.entity.Response;
import com.example.qa_back.utils.UploadFile;
import com.example.qa_back.utils.VoiceProcess;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 董帅
 * @date 2021/3/10 - 17:35
 */
@RestController
@RequestMapping("/api/voice")
public class VoiceController {

    /*
    * 功能：上传语音
    * param：语音文件，wav,flac,opus,mp3,m4a
    * return：第三个参数是一个String，前端要转成json对象来取值
    * */
    @PostMapping("uploadVoice")
    public Response uploadVoice(MultipartFile file) {
        String uploadVoice = UploadFile.uploadVoice(file);
        if (!uploadVoice.equals("error")) {
            String sentence = VoiceProcess.getSentence(uploadVoice);
            return new Response(1, "上传成功", sentence);
        } else {
            return new Response(0, "上传失败", null);
        }
    }
}
